-- item_per5floor
-- created by panyl
-- 每前进5层迷宫，获得N个XX

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 进入下层触发触发
    trigger = function(who, prop, arg)
        if who.type ~= OBJECT_TYPE_USER then
            return 0;
        end

        -- 客户端此时还在前一层，需要+1计算
        local floor = DungeonM.currentLayer() + 1;

        -- 不是在10层，不处理
        if floor % 5 ~= 0 then
            return 0;
        end

        local arr = {};
        if type(prop[2]) == 'string' then
            arr = string.explode(prop[2], "+");
        end

        local classId;

        if #arr > 1 then
            local rand = DungeonM.getRandSeed("item_per5floor");
            if prop[2] == "7168+7169" then
                -- 随机给灯油，劣质灯油：黄金灯油 = 8:2,特殊处理一下
                rand = rand % 10;
                if rand < 8 then
                    classId = tonumber(arr[1]);
                else
                    classId = tonumber(arr[2]);
                end
            else
                classId = tonumber(arr[rand % #arr + 1]);
            end
        elseif "component_1" == prop[2] then
            classId = FormulaM.invoke("FETCH_PROP_RANDOM_BONUS", prop[2]);
        else
            classId = tonumber(prop[2]);
        end

        local bonus = {1, classId, tonumber(prop[3])};
        BonusM.doBonus(bonus, "item_per5floor");

        EventMgr.fire(event.LAYER_BONUS_EVENT, { ["bonusList"] = {bonus}, });

        return prop[3];
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;

        local num = prop[3];
        local name = ItemM.query(prop[2], "name");

        -- 多种物品抽取某一种的，描述单独处理下
        if prop[2] == "component_1" then
            name = getLocStr("component");
        end

        desc = string.gsub(desc, "{0}", name);
        desc = string.gsub(desc, "{1}", num);

        return desc;
    end,

    record = function(target, prop, path)
        return false;
    end
};
